﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UClaimDemageControlAdd : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }
        protected override string DWZRef
        {
            get { return "UClaimDemageControlList"; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
                
            }
        }
        private void addmenu()
        {
            UClaimDemageControlInfo obj = Request.SerializableObject<UClaimDemageControlInfo>();
            //处理原材料号码 2013-02-04
            char[] caSplit = new char[] { ',' };
            string[] ItemCodes = GetRequestValue<string>("DetailItemCode", "").Split(caSplit);
            string[] Quantitys = GetRequestValue<string>("DetailQuantity", "").Split(caSplit);
            List<UClaimDemageControlOITMDetailInfo> list = new List<UClaimDemageControlOITMDetailInfo>();
            for (int index = 0; index < ItemCodes.Count(); index++)
            {
                string itemcode = ItemCodes[index];
                if (! string.IsNullOrEmpty(itemcode.Trim()))
                {
                    decimal Quantity = Convert.ToDecimal(Quantitys[index]);

                    UClaimDemageControlOITMDetailInfo detailObj = new UClaimDemageControlOITMDetailInfo();
                    detailObj.ItemCode = itemcode;
                    detailObj.ItemName = SBOController.GetHaveItemCode(itemcode);
                    detailObj.Quantity = Quantity;

                    list.Add(detailObj);
                }
            }


            this.AddLog(Permission.新增, obj);
            int r = UClaimDemageControlController.Add(obj);
            if (r>0)
            {
                UClaimDemageControlOITMDetailController.AddUClaimDemageControlOITMDetail(r, list);
                SuccessJson("添加成功", this.DWZRef);
            }
            else
            {
                ErrorJson("添加失败", this.DWZRef);
            }
        }
    }
}